const ADD = 'ADD';
const DEL = 'DEL';

const defaultAction = {
    type: ADD,
    preload: 0
}
const a = {
    id: 0
}

const samea = (state = a, action = defaultAction) => {
    let res = {...state};

    switch(action.type){
        case ADD:
        res = {...state, id: state.id + action.preload};break;
        case DEL:
        res = {...state, id: state.id - action.preload};break;
    }
    
    return res;
}

const doAdd = dispatch => dispatch => {
    setTimeout(()=>{
        dispatch({
            type: ADD,
            preload: 31
        })
    }, 3000)
}

const doDel = dispatch => dispatch => {
    setTimeout(()=>{
        dispatch({
            type: DEL,
            preload: 3
        })
    }, 3000)
}

export { samea, doAdd, doDel }
